<!--
 * @Author: XieQiu 雪球
 * @Date: 2021-05-10 15:06:59
 * @LastEditTime: 2022-02-21 09:59:10
 * @LastEditors: Please set LastEditors
 * @Description: 承租户奖惩信息页面
-->
<template>
  <BaseMainSlot>
    <template v-slot:searchbox>
      <div class="label-input mr-20 ml-20">
        <div class="label label-80">承租户姓名:</div>
        <div class="input">
          <el-select v-model="lessesId" filterable clearable>
            <el-option
              v-for="item in lessesArr"
              :key="item.lessesId"
              :label="item.lessee"
              :value="item.lessesId"
            />
          </el-select>
        </div>
      </div>
      <div class="label-input mr-20 ml-20">
        <div class="label label-80">信息类别:</div>
        <div class="input">
          <el-select v-model="category" filterable clearable>
            <el-option label="奖励" value="奖励" />
            <el-option label="惩罚" value="惩罚" />
          </el-select>
        </div>
      </div>
      <div class="label-input mr-20">
        <div class="label">时间选择:</div>
        <div class="input">
          <StartTimeEndTimeSelectionBox @startVal="startVal" @endVal="endVal" />
        </div>
      </div>
      <div class="search ml-20">
        <img src="~@/assets/action-bar-icon/search.png" @click="search" />
      </div>
    </template>

    <template v-slot:content>
      <el-table
        v-loading="loading"
        highlight-current-row
        :data="tableData"
        stripe
        border
        height="88%"
      >
        <el-table-column type="index" label="序号" width="50" />
        <el-table-column prop="lesseeName" label="姓名" width="250" />
        <el-table-column prop="category" label="信息类别" />
        <el-table-column prop="details" label="具体内容" />
        <el-table-column
          prop="rewardTime"
          :formatter="dateFormat"
          label="奖惩时间"
          min-width="100"
        />
      </el-table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
    </template>
  </BaseMainSlot>
</template>

<script>
import Pagination from "@/components/Pagination";
import awardPunishManage from "@/api/digital-operation/tenant-manage/award-punish-manage";
import tenantInfoManage from "@/api/digital-operation/tenant-manage/tenant-info";
import BaseMainSlot from "@/components/BaseMainSlot/kong.vue";
import StartTimeEndTimeSelectionBox from "@/components/StartTimeEndTimeSelectionBox"
import { mymixin } from "@/utils/mixin";
export default {
  name: "",
  components: { Pagination, BaseMainSlot, StartTimeEndTimeSelectionBox },
  mixins: [mymixin],
  data() {
    return {
      obj: {
        name: ""
      },
      // 承租户Id
      lessesId: "",
      // 信息类别
      category: "",
      //  承租户数组
      lessesArr: [],
      // 选中的数据项数组 ID组成
      inspectionTaskIdList: [],
      // 时间间隔
      rangeTime: "",
      // 巡查路线ID
      inspectionRouteId: "",
      startTime: "",
      endTime: ""
    };
  },
  watch: { },
  created() {
    //  查询所有承租户
    this.queryLessesByCondition();
  },
  mounted() {
    // 获取表格数据
    this.getTableDataList();
  },
  methods: {
    getTableDataList() {
      this.loading = true;
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        entity: {
          lessesId: this.lessesId,
          category: this.category,
          startTime: this.startTime,
          endTime: this.endTime
        }
      };
      awardPunishManage.getLessesRewardList(params).then(res => {
        this.loading = false;
        let data = res.data;
        // console.log(data);
        // 赋值总条数
        if (data) {
          this.totalSize = data.totalElements;
          // 赋值数组
          this.tableData = data.content;
          this.tableData.forEach(item => {
            this.lessesArr.forEach(itemTwo => {
              if (item.lessesId === itemTwo.lessesId) {
                this.$set(item, "lessee", itemTwo.lessee);
              }
            });
          });
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    // 时间转换
    dateFormat(row, colnum) {
      if (row.rewardTime) {
        return this.$moment(row[colnum.property]).format("YYYY-MM-DD HH:mm:ss");
      }
    },
    // 搜索框时间
    startVal(e) {
      this.startTime = e
    },
    endVal(e) {
      this.endTime = e
    },
    //  条件查询所有承租户
    async queryLessesByCondition() {
      const { data: res } = await tenantInfoManage.queryLessesByCondition(1);
      this.lessesArr = res;
    },
    search() {
      this.currentPage = 1;
      this.getTableDataList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.getTableDataList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.getTableDataList();
    }
  }
};
</script>

<style scoped lang="scss">
::v-deep .label {
  text-align: end;
  padding: 0 10px;
}
</style>
